package com.naiterui.ehp.bs.doctor.controller;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.domain.QuickReply;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.IQuickReplyService;
import com.naiterui.ehp.bs.doctor.utils.LimitValueConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 快捷回复控制类
 *
 * @version 2015年6月21日 下午6:03:39 by chenlin
 * @Description 概述
 */
@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.GRAPHIC_CONSULT})
@Controller
@RequestMapping("ad/quickReply")
public class AdQuickReplyController {

    @Autowired
    private IQuickReplyService quickReplyService;

    /**
     * <获取快捷回复>
     *
     * @param doctorId
     *
     * @return String <分组列表>
     *
     * @Throws 异常信息
     * @History 2015-6-20 上午11:59:15 by guoyongxiang
     */
    @ApiOperation(value = "获取快捷回复", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型：0:会话类（默认）， 1：评价回复", dataType = "int", required = false, paramType = "query")
    })
    @RequestMapping("list")
    @ResponseBody
    public List<QuickReply> list(Long doctorId, Integer type) {
        return quickReplyService.findQuickReplyByDoctorId(doctorId, type);
    }

    /**
     * <新增医生快捷回复>
     * <详细描述>
     *
     * @param doctorId
     * @param content
     *
     * @return String <返回值描述>
     *
     * @Throws 异常信息
     * @History 2015年6月21日 下午7:38:46 by chenlin change by linhf 2016-07-01 V2.5.0 添加校验参数长度
     */
    @ApiOperation(value = "新增快捷回复", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型：0:会话类（默认）， 1：评价回复", dataType = "int", required = false, paramType = "form")
    })
    @RequestMapping("add")
    @ResponseBody
    public void addQuickReply(Long doctorId, String content, Integer type) throws BusinessException {
        if (content == null || content.equals("")) {
            throw new BusinessException(ExceptionCodes.QUCIK_REPLY_NULL);
        }

        // V2.5.0 统一校验长度
        if (!LimitValueConfig.validateLimit(LimitValueConfig.LIMIT_QUICKREPLY, content)) {
            throw new BusinessException(ExceptionCodes.INVALID_CONTENT_LENGTH);
        }

        quickReplyService.saveQuickReply(doctorId, content, type);
    }

    /**
     * <删除医生患者快捷回复>
     */
    @ApiOperation(value = "删除快捷回复", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "ID列表(英文逗号分隔)", dataType = "String", required = true, paramType = "form")
    })
    @RequestMapping("remove")
    @ResponseBody
    public void removeGroup(Long doctorId, String ids) {
        quickReplyService.deleteQuickReplyByIds(ids);
    }

}
